package com.informationsystem.webapp.action;

import java.util.List;

import com.informationsystem.model.News;
import com.informationsystem.model.Notice;
import com.informationsystem.service.NewsManager;
import com.informationsystem.service.NoticeManager;

public class InfoCenter_Notice_Action extends BaseAction {
	private NoticeManager noticeManager;
	private List noticeList;
	private Notice notice;
	private Long id;

	public NoticeManager getNoticeManager() {
		return noticeManager;
	}

	public void setNoticeManager(NoticeManager noticeManager) {
		this.noticeManager = noticeManager;
	}

	public List getNoticeList() {
		return noticeList;
	}

	public void setNoticeList(List noticeList) {
		this.noticeList = noticeList;
	}

	public Notice getNotice() {
		return notice;
	}

	public void setNotice(Notice notice) {
		this.notice = notice;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String list() {
		setNoticeList(noticeManager.getNoticeList());
		return SUCCESS;
	}

	public String view() {
		if (getId() != null) {
			setNotice(noticeManager.get(getId()));
			notice.setViewTimes(notice.getViewTimes() + 1);
			noticeManager.save(notice);
		} else {
			setNotice(new Notice());
		}

		return SUCCESS;
	}
	
	public Boolean getShowattachments(){
		return notice.getAttachements().size()>0;
	}
}
